package main

import (
	"fmt"
	"regexp"
)

func main() {
	// "-" |  "0.008" | "0.008" | 127.0.0.1 | - | [19/OCT/2018:23:30:57 +0800] | "GET /AUTH/LOGIN HTTP/1.1" | 200 | 3552 | "HTTP://NEW.MOYOKEJI.COM/"  | "MOZILLA/5.0 (MACINTOSH; INTEL MAC OS X 10_14_0) APPLEWEBKIT/537.36 (KHTML, LIKE GECKO) CHROME/69.0.3497.100 SAFARI/537.36"
	//'"$http_x_forwarded_for" |  "$request_time" | "$upstream_response_time" | $remote_addr | $remote_user | [$time_local] | "$request" | '
	//'$status | $body_bytes_sent | "$http_referer"  | "$http_user_agent" ';

	str := `"-" |  "0.008" | "0.008" | 127.0.0.1 | - | [19/OCT/2018:23:30:57 +0800] | "GET /AUTH/LOGIN HTTP/1.1" | 200 | 3552 | "HTTP://NEW.MOYOKEJI.COM/"  | "MOZILLA/5.0 (MACINTOSH; INTEL MAC OS X 10_14_0) APPLEWEBKIT/537.36 (KHTML, LIKE GECKO) CHROME/69.0.3497.100 SAFARI/537.36"`
	//str:=`"-1" |  "0.008"`
	//str := `172.0.0.12 - - [04/Mar/2018:13:49:52 +0000]`
	//r := regexp.MustCompile(`([\d\.]+)\s+([^ \[]+)\s+([^ \[]+)\s+`)

	// \"([^"]+)\"  匹配 "-"
	//r := regexp.MustCompile(`\"([^"]+)\"\s+\|\s+\"([^"]+)\"\s+\|\s+([\d\.]+)\s+\|\s([^ \[]+)\s+\|\s+\[([^ \[]+)+\s`)
	r := regexp.MustCompile(`\"([^"]+)\"\s+\|\s+\"([^"]+)\"\s+\|\s+([\d\.]+)\s+\|\s([^ \[]+)\s+\|\s+\[(.*)\]\s+\|\s+\"(.*?)\"\s+\|\s+([\d]+)\s+\|\s+([\d]+)\s+\|\s+\"(.*?)\"\s+\|\s+\"(.*?)\"`)
	ret := r.FindStringSubmatch(str)
	for _, v := range ret {
		fmt.Println(v)
	}

	//str := `172.0.0.12 - - [04/Mar/2018:13:49:52 +0000] http "GET /foo?query=t HTTP/1.0" 200 2133 "-" "KeepAliveClient" "-" 1.005 1.854`
	//r := regexp.MustCompile(`([\d\.]+)\s+([^ \[]+)\s+([^ \[]+)\s+\[([^\]]+)\]\s+([a-z]+)\s+\"([^"]+)\"\s(\d{3})\s+(\d+)\s+\"([^"]+)\"\s+\"(.*?)\"([\d\.-]+)\"\s+([\d\.-]+)\s+([\d\.-]+)`)
	//
	//ret := r.FindStringSubmatch(str)
	//for _, v := range ret{
	//	fmt.Println(v)
	//}

}
